#include <bits/stdc++.h>
#define maxn 128
#define maxm 9102
using namespace std;

int head[maxn], nex[maxm], ver[maxm], w[maxm], cnt;
int n, m;
inline void add(int a, int b, int c)
{
    nex[++cnt] = head[a];
    head[a] = cnt;
    ver[cnt] = b;
    w[cnt] = c;
}
bool vis[maxn];
int dis[maxn];
bool dfs_spfa(int u)
{
    vis[u] = true;
    for (int i = head[u]; i; i = nex[i]) {
        int v = ver[i];
        if (dis[v] > dis[u] + w[i]) {
            dis[v] = dis[u] + w[i];
            if (vis[v] || !dfs_spfa(v))
                return false;
        }
    }
    vis[u] = false;
    return true;
}
int main()
{
    int t;
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d", &n, &m);
        memset(head, 0, sizeof(head));
        memset(vis, false, sizeof(vis));
        memset(dis, 0x3f, sizeof(dis));
        dis[n + 1] = 0;
        cnt = 0;
        for (int i = 1; i <= n; i++)
            add(n + 1, i, 0);
        for (int i = 1, u, v, w; i <= m; i++) {
            scanf("%d%d%d", &u, &v, &w);
            add(u - 1, v, w);
            add(v, u - 1, -w);
        }
        dfs_spfa(n + 1) ? puts("true") : puts("false");
    }
}
